package cn.echo.ecc.mq.producer;

import cn.echo.ecc.domain.MediaFile;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class CourseVideoPushProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public Boolean sendMessage(MediaFile mediaFile) {
        SendResult sendResult = rocketMQTemplate.syncSend("topic-coursevideo:tag-push", MessageBuilder.withPayload(mediaFile).build());
        return sendResult.getSendStatus() == SendStatus.SEND_OK ? true : false;
    }
 }
